	//I2C0模拟
	adi_gpio_OutputEnable(Port0,Pin4|Pin5,true);
	adi_gpio_PullUpEnable(Port0,Pin4|Pin5,true);
	adi_gpio_DriveStrengthEnable(Port0,Pin4|Pin5,true);
	
	//I2C模拟
	adi_gpio_OutputEnable(Port2,Pin4|Pin5,true);
	adi_gpio_PullUpEnable(Port2,Pin4|Pin5,true);
	adi_gpio_DriveStrengthEnable(Port2,Pin4|Pin5,true);

uint8_t I2C0_AN_Wait_Ack(void)
{
	uint8_t ucErrTime=0;	
	I2C0_SDA=1;
	I2C0_AN_SDA_IN();	 	
	delay_us(1);	   
	I2C0_SCL=1;
	delay_us(1);			
	while(I2C0_READ_SDA)
	{
		ucErrTime++;
		delay_us(1);
		if(ucErrTime>250)
		{
			I2C0_AN_Stop();
			return 1;
		}
	}
	I2C0_SCL=0;	   
	return 0;  
} 

#include "ADuCM4050.h"
#include "GPIO.h"
#include "DELAY.h"
#include "I2C0.h"

void I2C0_AN_SDA_OUT(void)
{
	adi_gpio_InputEnable(Port0,Pin5,false);
	adi_gpio_OutputEnable(Port0,Pin5,true);
	adi_gpio_PullUpEnable(Port0,Pin5,true);
	adi_gpio_DriveStrengthEnable(Port0,Pin5,true);
}

void I2C0_AN_SDA_IN(void)
{
	adi_gpio_OutputEnable(Port0,Pin5,false);
	adi_gpio_InputEnable(Port0,Pin5,true);
}

void I2C0_AN_Start(void)
{
	I2C0_AN_SDA_OUT();
	I2C0_SDA=1;	  	  
	I2C0_SCL=1;
	delay_us(4);
 	I2C0_SDA=0;
	delay_us(4);
	I2C0_SCL=0;
}

void I2C0_AN_Stop(void)
{
	I2C0_AN_SDA_OUT();
	I2C0_SCL=0;
	I2C0_SDA=0;
 	delay_us(4);
	I2C0_SCL=1; 
	I2C0_SDA=1;
	delay_us(4);							   	
}

uint8_t I2C0_AN_Wait_Ack(void)
{
	uint8_t ucErrTime=0;	
	I2C0_SDA=1;
	I2C0_AN_SDA_IN();	 	
	delay_us(1);	   
	I2C0_SCL=1;
	delay_us(1);			
	while(I2C0_READ_SDA)
	{
		ucErrTime++;
		delay_us(1);
		if(ucErrTime>250)
		{
			I2C0_AN_Stop();
			return 1;
		}
	}
	I2C0_SCL=0;	   
	return 0;  
} 

void I2C0_AN_Ack(void)
{
	I2C0_SCL=0;
	I2C0_AN_SDA_OUT();
	I2C0_SDA=0;
	delay_us(2);
	I2C0_SCL=1;
	delay_us(2);
	I2C0_SCL=0;
}

void I2C0_AN_No_Ack(void)
{
	I2C0_SCL=0;
	I2C0_AN_SDA_OUT();
	I2C0_SDA=1;
	delay_us(2);
	I2C0_SCL=1;
	delay_us(2);
	I2C0_SCL=0;
}

void I2C0_AN_Send_Byte(uint8_t txd)
{                        
  uint8_t t;   
  I2C0_AN_SDA_OUT(); 	    
  I2C0_SCL=0;//数据开始传输的时候需要拉低时钟线
  for(t=0;t<8;t++)
  {              
    I2C0_SDA=(txd&0x80)>>7;
    txd<<=1; 
		delay_us(2);   // 不同的器件有不同的要求，根据要求进行配置
		I2C0_SCL=1;
		delay_us(2); 
		I2C0_SCL=0;	
		delay_us(2);
  }	 
} 

uint8_t I2C0_AN_Read_Byte(void)
{
	unsigned char i,receive=0;
	I2C0_AN_SDA_IN();
  for(i=0;i<8;i++ )
	{
    I2C0_SCL=0; 
    delay_us(2);
		I2C0_SCL=1;
    receive<<=1;
    if(I2C0_READ_SDA) receive|=0x01;   
		delay_us(1); 
  }					 
  return receive;
}

uint8_t I2C0_AN_Slave_Ack(uint8_t slave_add)
{
	mux_PINS(0,4,0x0);
	mux_PINS(0,5,0x0);	
	uint8_t dat=0;
	I2C0_AN_Start();  
	I2C0_AN_Send_Byte((slave_add<<1)&0xFF);  
	dat=I2C0_AN_Wait_Ack();
	I2C0_AN_Stop();
	return dat;	
}

//void 	TMP75_WriteOneByte(uint8_t DeviceAdd,uint8_t PointAddr,uint8_t DataToWrite)
//{				
//	I2C0_AN_Start();  
//	I2C0_AN_Send_Byte(DeviceAdd);   	 
//	I2C0_AN_Wait_Ack();	   
//	I2C0_AN_Send_Byte(PointAddr);   
//	I2C0_AN_Wait_Ack();
//	I2C0_SDA=1;
//	I2C0_AN_Send_Byte(DataToWrite);
//	I2C0_AN_Wait_Ack();
//	I2C0_AN_Stop(); 
//	delay_ms(30);	 
//}

//void 	TMP75_WriteOneWord(uint8_t DeviceAdd,uint8_t PointAddr,uint16_t DataToWrite)
//{					
//	I2C0_AN_Start();  
//	I2C0_AN_Send_Byte(DeviceAdd);    
//	I2C0_AN_Wait_Ack();	   
//	I2C0_AN_Send_Byte(PointAddr);   
//	I2C0_AN_Wait_Ack();
//	I2C0_SDA=1;
//	I2C0_AN_Send_Byte((DataToWrite>>8)&0xff);
//	I2C0_AN_Wait_Ack();
//	I2C0_AN_Send_Byte(DataToWrite&0xff);
//	I2C0_AN_Wait_Ack(); 
//	I2C0_AN_Stop();
//	delay_ms(30);	 
//} 

//uint8_t TMP75_ReadOneByte(uint8_t DeviceAdd, uint8_t PointAddr)
//{
//	uint8_t temp=0;
//	I2C0_AN_Start();  
//	I2C0_AN_Send_Byte(DeviceAdd);   
//	I2C0_AN_Wait_Ack();
//	I2C0_AN_Send_Byte(PointAddr);
//	I2C0_AN_Wait_Ack();
//	I2C0_AN_Start();
//	I2C0_AN_Send_Byte(DeviceAdd|0x00);
//	I2C0_AN_Wait_Ack();    
//	temp=I2C0_AN_Read_Byte();
//	I2C0_AN_Stop();
//	return temp;
//}

//uint16_t TMP75_ReadOneWord(uint8_t DeviceAdd, uint8_t PointAddr)
//{				  
//	uint16_t tempH=0;
//	uint16_t tempL=0;
//	uint16_t temp=0;
//	I2C0_AN_Start();  
//	I2C0_AN_Send_Byte(DeviceAdd);   
//	I2C0_AN_Wait_Ack();
//	I2C0_AN_Send_Byte(PointAddr); 
//	I2C0_AN_Wait_Ack();
// 
//	I2C0_AN_Start();
//	I2C0_AN_Send_Byte(DeviceAdd|0x00);  
//	I2C0_AN_Wait_Ack();    
//	tempH=I2C0_AN_Read_Byte();
//	I2C0_AN_Ack();
//	I2C0_SDA=1;    
//	tempL=I2C0_AN_Read_Byte();
//	I2C0_AN_No_Ack();
//	I2C0_AN_Stop();
//	temp = (tempH << 8) | tempL ;
//	temp = (temp >> 4); 
//	return temp;
//}


